package com.kaixuan.mvvmdemo;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.kaixuan.mvvmdemo.databinding.ActivityLoginBinding;
import com.kaixuan.mvvmdemo.view.ILoginView;
import com.kaixuan.mvvmdemo.viewmodule.LoginViewModule;

public class LoginActivity extends AppCompatActivity implements ILoginView {

    ActivityLoginBinding binding;
    LoginViewModule loginViewModule = new LoginViewModule(this);
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_login);
        binding.setActivity(this);
    }

    public void onLoginClick(View view){
        loginViewModule.login();
    }

    @Override
    public String getUserName() {
        return binding.username.getText().toString();
    }

    @Override
    public String getPassword() {
        return binding.password.getText().toString();
    }

    @Override
    public void onLoginFail(String errorMsg) {
        Snackbar.make(binding.getRoot(),errorMsg,Snackbar.LENGTH_SHORT).show();
    }

    @Override
    public void onLoginSuccess(String msg) {
        Snackbar.make(binding.getRoot(),msg,Snackbar.LENGTH_SHORT).show();
    }
}
